<?php
class NguonvonsController extends AppController {

	var $name = 'Nguonvons';

	function index() {
		$this->Nguonvon->recursive = 0;
		$this->set('nguonvons', $this->paginate('Nguonvon'));
	}

	

	function add() {
		if (!empty($this->data)) {
			$this->Nguonvon->create();
			if ($this->Nguonvon->save($this->data)) {
				$this->Session->setFlash(__('The nguonvon has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Dữ liệu được lưu, vui lòng thử lại', true));
			}
		}
		$loaivons=$this->Nguonvon->Loaivon->find('list',array('fields'=>array('id','loaivon')));
		$this->set(compact('loaivons'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid nguonvon', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Nguonvon->save($this->data)) {
				$this->Session->setFlash(__('The nguonvon has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Dữ liệu được lưu, vui lòng thử lại', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Nguonvon->read(null, $id);
		}
		$loaivons=$this->Nguonvon->Loaivon->find('list',array('fields'=>array('id','loaivon')));
		$this->set(compact('loaivons'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for nguonvon', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Nguonvon->delete($id)) {
			$this->Session->setFlash(__('Nguonvon deleted', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->Session->setFlash(__('Dữ liệu được lưu, vui lòng thử lại', true));
		$this->redirect(array('action' => 'index'));
	}
}
